package njust.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import njust.dao.MessageDao;
import njust.domain.Image;
import njust.domain.Message;

public class MessageDaoImpl extends HibernateDaoSupport implements MessageDao{

	

	@Override
	public boolean addMessage(Message message) {
		this.getHibernateTemplate().save(message);
		return true;
	}

	@Override
	public boolean deleteMessage(int id) {
		Message message = (Message) this.getHibernateTemplate().get(Message.class, id);
		this.getHibernateTemplate().delete(message);
		return true;
	}

	@Override
	public List getAllMessage() {
		List list = new ArrayList();
		// this.getHibernateTemplate().setCacheQueries(true);
		list = this.getHibernateTemplate()
				.find("from Message order by MessageId desc");
		return list;
	}

	@Override
	public Message getMessageById(int id) {
		Message message = this.getHibernateTemplate().get(Message.class, id);
		return message;
	}
	

}
